//
//  MyInfoViewController.m
//  ZhouProject
//
//  Created by Dlrj on 14-12-15.
//  Copyright (c) 2014年 admin. All rights reserved.
//

#import "MyInfoViewController.h"
#import "EditMyInfoViewController.h"
#import "LoginViewController.h"
#import "XiuGaiMiMaViewController.h"
#import "XiaLa.h"
#import "XiuGaiXinXi.h"
#define widthMargin 25
#define labelWidth  63
#define labelMargin 95
#define xiantiaoWidth 300
#define xiantiaoHeight 1
#define xiantiaoWidthMargin 10
#define xiantiaoHeightMargin 90

@implementation MyInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeValue:) name:@"UpdateInfoSuccess" object:nil];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"我的资料";
    
    UILabel *xiantiaoLab = [[UILabel alloc] initWithFrame:CGRectMake(xiantiaoWidthMargin, kH(xiantiaoHeightMargin), xiantiaoWidth, xiantiaoHeight)];
    [xiantiaoLab setBackgroundColor:[UIColor lightGrayColor]];
    [self.view addSubview:xiantiaoLab];
    
    UIImageView *imagePhone = [[UIImageView alloc] initWithFrame:CGRectMake(kW(21), kH(102), kW(21), kH(21))];
    imagePhone.image = [UIImage imageNamed:@"bindphone.png"];
    [self.view addSubview:imagePhone];
    
    UILabel * labPhone = [[UILabel alloc]initWithFrame:CGRectMake(kW(20+widthMargin), kH(100), kW(labelWidth), kH(25))];
    labPhone.text = @"手机号:";
    labPhone.textAlignment = NSTextAlignmentRight;
    labPhone.textColor = [UIColor blackColor];
    [self.view addSubview:labPhone];
    
    xiantiaoLab = [[UILabel alloc] initWithFrame:CGRectMake(xiantiaoWidthMargin, kH(xiantiaoHeightMargin+50), xiantiaoWidth, xiantiaoHeight)];
    [xiantiaoLab setBackgroundColor:[UIColor lightGrayColor]];
    [self.view addSubview:xiantiaoLab];
    
    UIImageView *imageType = [[UIImageView alloc] initWithFrame:CGRectMake(kW(21), kH(152), kW(21), kH(21))];
    imageType.image = [UIImage imageNamed:@"type.png"];
    [self.view addSubview:imageType];
    
    UILabel * labType = [[UILabel alloc]initWithFrame:CGRectMake(kW(20+widthMargin), kH(150), kW(labelWidth), kH(25))];
    labType.text = @"类   别:";
    labType.textAlignment = NSTextAlignmentRight;
    labType.textColor = [UIColor blackColor];
    [self.view addSubview:labType];
    
    xiantiaoLab = [[UILabel alloc] initWithFrame:CGRectMake(xiantiaoWidthMargin, kH(xiantiaoHeightMargin+100), xiantiaoWidth, xiantiaoHeight)];
    [xiantiaoLab setBackgroundColor:[UIColor lightGrayColor]];
    [self.view addSubview:xiantiaoLab];
    
    UIImageView *image4s = [[UIImageView alloc] initWithFrame:CGRectMake(kW(21), kH(202), kW(21), kH(21))];
    image4s.image = [UIImage imageNamed:@"username.png"];
    [self.view addSubview:image4s];
    
    UILabel * lab4s = [[UILabel alloc]initWithFrame:CGRectMake(kW(20+widthMargin), kH(200), kW(labelWidth), kH(25))];
    lab4s.text = @"4S  店:";
    lab4s.textAlignment = NSTextAlignmentRight;
    lab4s.textColor = [UIColor blackColor];
    [self.view addSubview:lab4s];
    
    xiantiaoLab = [[UILabel alloc] initWithFrame:CGRectMake(xiantiaoWidthMargin, kH(xiantiaoHeightMargin+150), xiantiaoWidth, xiantiaoHeight)];
    [xiantiaoLab setBackgroundColor:[UIColor lightGrayColor]];
    [self.view addSubview:xiantiaoLab];
    
    UIImageView *imageZone = [[UIImageView alloc] initWithFrame:CGRectMake(kW(21), kH(252), kW(21), kH(21))];
    imageZone.image = [UIImage imageNamed:@"address.png"];
    [self.view addSubview:imageZone];
    
    UILabel * labZone = [[UILabel alloc]initWithFrame:CGRectMake(kW(20+widthMargin), kH(250), kW(labelWidth), kH(25))];
    labZone.text = @"区   域:";
    labZone.textAlignment = NSTextAlignmentRight;
    labZone.textColor = [UIColor blackColor];
    [self.view addSubview:labZone];
    
    _txtPhone = [[UITextField alloc]initWithFrame:CGRectMake(kW(labelMargin+widthMargin), kH(100), kW(200), kH(25))];
    _txtPhone.backgroundColor = [UIColor whiteColor];
    _txtPhone.returnKeyType = UIReturnKeyDone;
    _txtPhone.placeholder = @"有效的手机号";
    _txtPhone.text = self.strloginName;
    _txtPhone.userInteractionEnabled = NO;
//    _txtPhone.layer.borderWidth = 1.0f;//边框宽度
//    _txtPhone.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    _txtPhone.clipsToBounds = YES;//内容不超出边框
 
    [self.view addSubview:_txtPhone];
    
    xiantiaoLab = [[UILabel alloc] initWithFrame:CGRectMake(xiantiaoWidthMargin, kH(xiantiaoHeightMargin+200), xiantiaoWidth, xiantiaoHeight)];
    [xiantiaoLab setBackgroundColor:[UIColor lightGrayColor]];
    [self.view addSubview:xiantiaoLab];
    
    _txtType = [[UITextField alloc]initWithFrame:CGRectMake(kW(labelMargin+widthMargin), kH(150), kW(200), kH(25))];
    _txtType.backgroundColor = [UIColor whiteColor];
    _txtType.returnKeyType = UIReturnKeyDone;
    _txtType.placeholder = @"类别";
    _txtType.userInteractionEnabled = NO;
    for (int i = 0; i < self.arr.count; i++)
    {
        XiaLa * model = [self.arr objectAtIndex:i];
        if ([model.strcategoryId isEqualToString:self.strcategoryId]) {
            _txtType.text = model.strcategoryName;
        }
    }
//    _txtType.layer.borderWidth = 1.0f;//边框宽度
//    _txtType.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    _txtType.clipsToBounds = YES;//内容不超出边框
    [self.view addSubview:_txtType];
    
    _txt4S = [[UITextField alloc]initWithFrame:CGRectMake(kW(labelMargin+widthMargin), kH(200), kW(200), kH(25))];
    _txt4S.backgroundColor = [UIColor whiteColor];
    _txt4S.returnKeyType = UIReturnKeyDone;
    _txt4S.placeholder = @"4S店";
    _txt4S.text = self.strshopName;
    _txt4S.userInteractionEnabled = NO;
//    _txt4S.layer.borderWidth = 1.0f;//边框宽度
//    _txt4S.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    _txt4S.clipsToBounds = YES;//内容不超出边框
    [self.view addSubview:_txt4S];
    
    _txtZone = [[UITextField alloc]initWithFrame:CGRectMake(kW(labelMargin+widthMargin), kH(250), kW(200), kH(25))];
    _txtZone.backgroundColor = [UIColor whiteColor];
    _txtZone.returnKeyType = UIReturnKeyDone;
    _txtZone.placeholder = @"区域";
    _txtZone.text = self.strshopArea;
    _txtZone.userInteractionEnabled = NO;
//    _txtZone.layer.borderWidth = 1.0f;//边框宽度
//    _txtZone.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    _txtZone.clipsToBounds = YES;//内容不超出边框
    [self.view addSubview:_txtZone];
    
    UIButton * btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnLogin.frame = CGRectMake(kW(40), kH(350), kW(240), kH(35));
    [btnLogin setTitle:@"编辑资料" forState:UIControlStateNormal];
    btnLogin.backgroundColor = [UIColor whiteColor];
    [btnLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnLogin.layer.borderWidth = 1.0f;//边框宽度
    btnLogin.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    btnLogin.layer.cornerRadius = 5.0;//设置圆角
    btnLogin.clipsToBounds = YES;//内容不超出边框
    [btnLogin addTarget:self  action:@selector(clickbianji) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnLogin];
    
    UIButton * btnReg = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnReg.frame = CGRectMake(kW(40), kH(400), kW(240), kH(35));
    [btnReg setTitle:@"修改密码" forState:UIControlStateNormal];
    btnReg.backgroundColor = [UIColor whiteColor];
    [btnReg setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnReg.layer.borderWidth = 1.0f;//边框宽度
    btnReg.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    btnReg.layer.cornerRadius = 5.0;//设置圆角
    btnReg.clipsToBounds = YES;//内容不超出边框
    [btnReg addTarget:self  action:@selector(clickxiugai) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnReg];
    
    UIButton * btntuichu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btntuichu.frame = CGRectMake(kW(40), kH(450), kW(240), kH(35));
    [btntuichu setTitle:@"退出登录" forState:UIControlStateNormal];
    btntuichu.backgroundColor = [UIColor whiteColor];
    [btntuichu setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btntuichu.layer.borderWidth = 1.0f;//边框宽度
    btntuichu.layer.borderColor = [UIColor colorWithRed:212.0 / 255 green:212.0 / 255 blue:212.0 / 255 alpha:1].CGColor;//边框颜色
    btntuichu.layer.cornerRadius = 5.0;//设置圆角
    btntuichu.clipsToBounds = YES;//内容不超出边框
    [btntuichu addTarget:self  action:@selector(clicktuichu) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btntuichu];
}

- (void)changeValue:(NSNotification *)notificaion{
    NSDictionary * userInfo = notificaion.userInfo;
    XiuGaiXinXi * model = [userInfo objectForKey:@"return"];
    self.strcategoryId = model.strTypeid;
    self.strshopArea = model.strZone;
    self.strshopName = model.str4s;
    _txtType.text = model.strType;
    _txt4S.text = model.str4s;
    _txtZone.text = model.strZone;
}

-(void)clickxiugai
{
    XiuGaiMiMaViewController * vc = [[XiuGaiMiMaViewController alloc]init];
    vc.struserId = self.struserId;
    [vc setHidesBottomBarWhenPushed: YES];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)clickbianji
{
    EditMyInfoViewController * vc = [[EditMyInfoViewController alloc]init];
    vc.struserId = self.struserId;
    vc.strloginName = self.strloginName;
    vc.strpassword = self.strpassword;
    vc.strcategoryId = self.strcategoryId;
    vc.strshopArea = self.strshopArea;
    vc.strshopName = self.strshopName;
    [vc setHidesBottomBarWhenPushed: YES];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)clicktuichu
{
    LoginViewController * vc = [[LoginViewController alloc]init];
    [self defaultSaveuseraccount:@""];
    [self defaultSavePassword:@""];
    [vc setHidesBottomBarWhenPushed: YES];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)defaultSaveuseraccount:(NSString*)a
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:a  forKey:@"useraccount"];
    [defaults synchronize];
}

-(void)defaultSavePassword:(NSString*)a

{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    
    [defaults setObject:a  forKey:@"Password"];
    
    [defaults synchronize];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
